﻿@{
    ViewBag.Title = "用户中心";
    Layout = "~/Views/Shared/_layoutPersonal.cshtml";
}
@Styles.Render("~/Content/css/userInfo")

<article class="main">
    <div class="lay">
        <nav class="mod_nav">
            <div class="lay_left">
                <a class="nav_back" href='@Url.Content("~/")Home/Index'><img src="/images/TurnBackNormal.png"></a>
                <span>用户中心</span>
            </div>
        </nav>

        <div class="lay_top">
            <section class="mod_UserInfo">
                <div class="UserInfo_head"></div>
                <div class="UserInfo_note" style="display: none;">未登录</div>
                <div class="UserInfo_Number" id="userName"></div>
            </section>

            <section class="mod_content">
                <a class="content_order" onclick="getOrderList()">
                    <span class="icon"><img src="/images/OrderList.png" /></span>
                    <span class="text">我的订单</span>
                    <span class="right_message" id="unpickedOrderNum"></span>
                </a>
                <a class="content_address" onclick="getDeliveryAddr()">
                    <span class="icon"><img src="/images/DeliveryAddr.png" /></span>
                    <span class="text">我的收货地址</span>
                </a>
                <a class="content_feedback" onclick="feedback()">
                    <span class="icon"><img src="/images/Feedback.png"></span>
                    <span class="text">意见反馈</span>
                </a>
                <a class="content_address" href="@Url.Content("~/")Other/About">
                    <span class="icon"><img src="/images/About.png" /></span>
                    <span class="text">关于</span>
                </a>
            </section>
        </div>
    </div>
    <div class="lay_bottom">
        <a class="logout" onclick="logout()">退出登录</a>
    </div>
</article>

<script>
    window.onload = function () {
        var isLog = UserInfoMgr.isLogIn();
        if (isLog) {
            loginShow();
        } else {
            logoutShow();
        }
    }

    function loginShow() {
        $('.UserInfo_head').html('<a><img src="/images/icon_login.png" class="UserInfoHeadImg" alt="头像" /></a>');
        var userName = UserInfoMgr.getUserID();
        $('.UserInfo_Number').text(userName);
        var unpickNum = UserInfoMgr.getUnpickNum();
        var unpickHelp = unpickNum + '个未收货订单';
        $('#unpickedOrderNum').text(unpickHelp);
        if (unpickNum == 0)
        {
            $('#unpickedOrderNum').removeClass("highlight");
            $('#unpickedOrderNum').addClass("gray");
        }
        else
        {
            $('#unpickedOrderNum').removeClass("gray");
            $('#unpickedOrderNum').addClass("highlight");
        }
        $("#logoutBtn").show();
    }

    function logoutShow() {
        $('.UserInfo_head').html('<a><img src="/images/icon_normal.png" class="UserInfoHeadImg" onclick = "login()"></a>');
        $('.UserInfo_Number').text("点击头像登录");
        $('#unpickedOrderNum').text("0个未收货订单");
        $('#unpickedOrderNum').hide();
        $('.lay_bottom').hide();
    }

    function logout() {
        UserInfoMgr.logout();
        logoutShow();
    }

    function login() {
        window.location.href = '@Url.Content("~/")' + 'User/Login';
    }

    function feedback() {
        window.location.href = '@Url.Content("~/")' + 'Other/Feedback';
    }

    function getOrderList() {
        if (UserInfoMgr.isLogIn()) {
            window.location.href = '@Url.Content("~/")' + 'Order/Index';
        } else {
            window.location.href = '@Url.Content("~/")' + 'User/Login?url=/Order/Index';
        }
    }

    function getDeliveryAddr() {
        if (UserInfoMgr.isLogIn()) {
            window.location.href = '@Url.Content("~/")' + 'DeliveryAddr/Index';
        } else {
            window.location.href = '@Url.Content("~/")' + 'User/Login?url=/DeliveryAddr/Index';
        }
    }
</script>
